/**
 * 
 */
package com.zqp.web.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.zqp.web.fiter.TimeFilter;
import com.zqp.web.intercepter.TimerIntercepter;

/**
 * @author zqp
 * 
 */
//@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{

	@Autowired
	TimerIntercepter timerIntercepter;
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(timerIntercepter);
	}
	
	/**
	 * 拦截异步请求的..
	 * @return
	 */
//	@Override
//	public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
//		// TODO Auto-generated method stub
//		super.configureAsyncSupport(configurer);
//	}

	@Bean
	public FilterRegistrationBean timerFilter() {

		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		TimeFilter t = new TimeFilter();

		registrationBean.setFilter(t);
		List<String> urls = new ArrayList<String>();

		urls.add("/*");
		
		registrationBean.setUrlPatterns(urls);
		return registrationBean;
	}
}
